package com.gebogebo.android.pub;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class PicYourBattleActivity extends Activity implements OnClickListener {
	private static final String lg = "main";

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        findViewById(R.id.button).setOnClickListener(this);
        findViewById(R.id.CreateDoddleButton).setOnClickListener(this);
    }

	public void onClick(View v) {
		int id = v.getId();
		
		switch (id) {
		case R.id.button:
			Intent i = new Intent(Intent.ACTION_PICK,
		               android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
			startActivityForResult(i, Constants.PICK_IMAGE_REQ_CODE); 
			break;
			
		case R.id.CreateDoddleButton:
			Intent createDoddleIntent = new Intent(this, createDoddleActivity.class);
			startActivityForResult(createDoddleIntent,Constants.SAVE_CREATED_DOODLE_CODE);
			break;

		default:
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {		
		switch (requestCode) {
		case Constants.PICK_IMAGE_REQ_CODE:
			Intent viewImageIntent = new Intent(Constants.VIEW_IMAGE_ACTION);
			viewImageIntent.putExtra(ViewImageActivity.IMAGE_URL_EXTRA, data.getData());
			startActivity(viewImageIntent);
			break;
		case Constants.SAVE_CREATED_DOODLE_CODE:
			Bundle extras = (data != null)? data.getExtras() : null;
			Bitmap myExtras = null;
			Log.v("File output file","File was here");
			if (extras != null && extras.containsKey("Testing")){
				Log.v("Testing",extras.getString("Testing"));
				ImageView image = (ImageView) findViewById(R.id.imageView1);
				Uri imgUri=Uri.parse(extras.getString("Testing"));
				image.setImageURI(imgUri);
			}
			break;
		default:
			Log.v("Button click","Default");
			break;
		}
	}
}
